package com.itheima02;

import java.util.Scanner;

public class ThrowsDemo01 {
    public static void main(String[] args) {
        Student stu = new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名:" );
        String name = sc.nextLine();
        stu.setName(name);
        System.out.println("请输入年龄:");
        while (true) {
            try {
                String age = sc.nextLine();
                int age1 =Integer.parseInt(age);
                stu.setAge(age1);
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("请输入一个合法的年龄数据");
            } catch (Student.AgeOutofBoundsException e){
                e.printStackTrace();
                System.out.println("请输入正确的年龄");
            }
        }
        System.out.println(stu);


    }
}
